home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 480.lha / SmartField / Docs / Structure Definitions.pp / Structure Definitions
Encoding:
Text File  |  1991-02-11  |  19.1 KB  |  451 lines

  1. STRUCTURE DEFINITIONS
  2.  
  3.  
  4. struct Field
  5. ------------
  6.  
  7. This is the structure which all fields use.  It has the following format:
  8.  
  9.     struct Field {
  10.         struct Field *PrevField;
  11.         struct Field *NextField;
  12.         UBYTE  *Buffer;
  13.         UBYTE  *UndoBuffer;
  14.         UBYTE  *DupBuffer;
  15.         UBYTE  FrontPen;
  16.         UBYTE  BackPen;
  17.         UBYTE  Style;
  18.         UBYTE  Enabled;
  19.         struct FieldMask *Mask;
  20.         USHORT Flags;
  21.         SHORT  Left;
  22.         SHORT  Top;
  23.         SHORT  Right;
  24.         SHORT  Bottom;
  25.         SHORT  MaxChars;
  26.         SHORT  NumChars;
  27.         SHORT  DispChars;
  28.         SHORT  BufferPos;
  29.         SHORT  DispPos;
  30.         struct IntuiText *FieldTitle;
  31.         struct Border *FieldBorder;
  32.         struct Image *FieldImage;
  33.         SHORT  FieldID;
  34.         APTR   UserPtr;
  35.         LONG   Reserved1;
  36.         LONG   Reserved2;
  37.     };
  38.  
  39.     The individual elements are defined as follows:
  40.  
  41.     struct Field *PrevField
  42.  
  43.         This is a pointer to the previous field in your field list.  Perhaps
  44.         the easiest way to set up field lists is to pre-initialize them as
  45.         global variables so that all routines in your program may access
  46.         them.  Unlike Intuition gadgets which should be defined in reverse
  47.         order so that the NextGadget pointer points to an already defined
  48.         gadget, you should define the fields in the order of cursor travel,
  49.         linking them together with the PrevField pointer.  Of course, the
  50.         PrevField pointer for the first field in the list should be set to
  51.         NULL.  Then before you display the fields, you should call the
  52.         field_link() function to set the NextField pointers.  If you open
  53.         your field devices with the field_open() function, however, this is
  54.         done for you.
  55.  
  56.     struct Field *NextField
  57.  
  58.         This is a pointer to the next field in your field list.  If you are
  59.         pre-initializing your fields, set this field to LATER (which is
  60.         defined in toolkit/toolkit.h as NULL) for all fields except the final
  61.         field which can be set to NULL.  This field is then filled in when
  62.         you call the field_link() or field_open() functions.  Because many of
  63.         the SmartFields functions access this pointer, be sure to set this
  64.         parameter immediately.
  65.  
  66.     UBYTE *Buffer
  67.  
  68.         This is a pointer to the null-terminated string which will hold the
  69.         contents of the field.  It should be defined to be at least as large
  70.         as MaxChars to prevent the overwriting of succeeding locations in
  71.         memory.  All functions (except the field_reshow() function) expect
  72.         this buffer to exist and will crash if this pointer is invalid.
  73.  
  74.     UBYTE *UndoBuffer
  75.  
  76.         This is a pointer to a null-terminated string which will hold the
  77.         "undo" contents of the field.  The contents of a field are copied
  78.         into its undo buffer when the cursor first appears in the field or if
  79.         the contents of the field are deleted with the field_delete()
  80.         function.  The contents of this buffer are then replaced into the
  81.         field when the field_restore() function is called.  This buffer does
  82.         not have to be defined, but if it is, it should be defined to be at
  83.         least as large as MaxChars to prevent the overwriting of succeeding
  84.         locations in memory.  If you do not wish to provide an UndoBuffer,
  85.         set this pointer to NULL.  Then if a user invokes a command which
  86.         would require an UndoBuffer (such as CTRL-X and CTRL-R), the screen
  87.         will flash indicating that the buffer does not exist.  Because only
  88.         one field at a time may be active, you may supply a single undo
  89.         buffer for multiple fields.  The buffer must be defined to be at
  90.         least as large as the largest MaxChars value in any of the fields
  91.         using this buffer.  Because providing a single undo buffer for many
  92.         fields can confuse the user, this method is not recommended.
  93.  
  94.     UBYTE *DupBuffer
  95.  
  96.         This is a pointer to a null-terminated string which will hold the
  97.         contents of the field after the field has been cleared by the
  98.         field_clear() function.  Then upon invocation of the field_dup()
  99.         function, the contents of this buffer will be copied into the field.
  100.         This buffer does not have to be defined, but if it is, it should be
  101.         defined to be at least as large as MaxChars to prevent the
  102.         overwriting of succeeding locations in memory.  If you do not wish to
  103.         provide a DupBuffer, set this pointer to NULL.  Then if a user
  104.         invokes the dup command (CTRL-D) which requires the DupBuffer, the
  105.         screen will flash indicating that the buffer does not exist.
  106.  
  107.     UBYTE FrontPen
  108.  
  109.         This is the foreground color of the field characters.  This has
  110.         nothing to do with the color of the text in the field title which you
  111.         specify in the IntuiText structure, however.  The FrontPen can be any
  112.         value from 0 to 7, and other values may produce strange results.
  113.         Only values 0 through 3 are valid for fields in windows rendered in
  114.         the Workbench screen.  These values represent the colors blue, white,
  115.         black, and orange, respectively, with the default Workbench settings.
  116.  
  117.     UBYTE BackPen
  118.  
  119.         This is the color of the background of the field characters.  This
  120.         parameter must have the same values as listed above for the FrontPen.
  121.         Note that if the FrontPen and BackPen are equal, the field text will
  122.         be invisible.  If you set the BackPen equal to a color other than the
  123.         background color of the window, the field_clear() function renders a
  124.         square the size of the input field in the BackPen color.  Use the
  125.         graphic rendition test program to view this effect.
  126.  
  127.     UBYTE Style
  128.  
  129.         This is the style of the field text.  Use the flags as defined in
  130.         console/console.h:  CON_PLAIN, CON_BOLD, CON_ITALIC, CON_UNDERSCORE,
  131.         CON_INVERSE.  You can also OR the flags to produce a combined effect.
  132.         For example:  CON_ITALIC | CON_UNDERSCORE will create an underlined-
  133.         italic style.
  134.  
  135.     UBYTE Enabled
  136.  
  137.         This flag determines whether input is accepted into this field.  Use
  138.         the FIELD_ENABLED and FIELD_DISABLED flags as defined in console/
  139.         fields.h to provide for upward compatibility.  Do not change this
  140.         flag manually.  Instead, use the field_disable() and field_enable()
  141.         functions.
  142.  
  143.     struct FieldMask *Mask
  144.  
  145.         This is a pointer to the input mask for the field.  See the FieldMask
  146.         structure definition for more information.  If this is set to NULL,
  147.         then no input checking is done and all input characters are accepted.
  148.  
  149.     USHORT Flags
  150.  
  151.         This field is not used at this time, but was provided for future use.
  152.         For upward compatibility, set this field to 0 and do not modify it.
  153.  
  154.     SHORT Left, Top
  155.  
  156.         These contain the horizontal and vertical window pixels of the upper
  157.         left corner of the first character in the field.  See the "Field
  158.         Layout" section for more information.
  159.  
  160.     SHORT Right, Bottom
  161.  
  162.         These contain the calculated horizontal and vertical pixels of the
  163.         bottom right end of the field.  You may initialize these values to
  164.         zero because the field_refresh() function calculates these based on
  165.         the maximum number of characters allowed in the field and the size of
  166.         each character according to the tf_XSize and tf_YSize parameters
  167.         contained in the IFont structure pointed to in the Window structure.
  168.  
  169.     SHORT MaxChars
  170.  
  171.         This is the maximum number of characters including the terminal null
  172.         that may be input into this field.  Thus, there will be no more that
  173.         MaxChars-1 characters visible in the field at any time.  Be sure to
  174.         define all buffers used by this field to be at least MaxChars long.
  175.         Once set for a field, this value should not be modified until the
  176.         field is removed from the window.
  177.  
  178.     SHORT NumChars
  179.  
  180.         This is the current number of characters in the field's buffer not
  181.         including the terminal null.  Thus, this value will always be less
  182.         than MaxChars (because MaxChars will always be at least one character
  183.         larger because of the terminal null).  Do not modify this value in
  184.         the calling program.  If you wish to change the contents of a field,
  185.         change the contents of the Buffer, then call the field_redisplay()
  186.         function.
  187.  
  188.     SHORT DispChars
  189.  
  190.         This is the number of characters currently visible in the field.
  191.         This is not currently used but was provided for upward compatibility.
  192.         Initialize this parameter to zero and do not modify it.
  193.  
  194.     SHORT BufferPos
  195.  
  196.         This is the current cursor position in the Buffer of the field.  Note
  197.         that the first character in the field occupies BufferPos zero
  198.         (because the buffer is a string).  A value does not imply that the
  199.         field is currently active.  The currently active field is pointed to
  200.         by the CurrentField parameter in the FieldHeader structure.  The
  201.         BufferPos value is stored even after the cursor has left this field
  202.         so that when the cursor returns, it will return to the exact position
  203.         it was in when it left.  Warning: do not modify this value.  Use one
  204.         of the cursor positioning functions instead.
  205.  
  206.     SHORT DispPos
  207.  
  208.         This parameter is not currently used but was provided for upward
  209.         compatibility.  Initialize this parameter to zero and do not modify
  210.         it.
  211.  
  212.     struct IntuiText *FieldTitle
  213.  
  214.         This is a pointer to an IntuiText structure which will be displayed
  215.         as the field title by the field_refresh() function.  If you wish no
  216.         title, set this pointer to NULL.  If you desire more than one title,
  217.         link the text together using the NextText pointer in the Intuitext
  218.         structure.  The text will be rendered in reference to the Left and
  219.         Top edges of the field.
  220.  
  221.     struct FieldBorder *FieldBorder
  222.  
  223.         This is a pointer to a Border structure which will be rendered in
  224.         reference to the Left and Top edges of the field.  If you do not want
  225.         a border, set this pointer to NULL.  If you want more than one
  226.         border, link the borders together using the NextBorder pointer in the
  227.         Border structure.
  228.  
  229.     struct Image *FieldImage
  230.  
  231.         This is a pointer to an Image structure which will be rendered in the
  232.         window's rastport in reference to the Left and Top edges of the
  233.         field.  If you do not want an image, set this pointer to NULL.  If
  234.         you want more than one image, link the images together using the
  235.         NextImage pointer in the Image structure.  The field_refresh()
  236.         function renders the field in the following order:  images, borders,
  237.         title, field text.
  238.  
  239.     SHORT FieldID
  240.  
  241.         This field is provided for your own use to label and identify the
  242.         fields.  The most common use of this field is in switch statements.
  243.         This parameter is ignored by SmartFields.
  244.  
  245.     APTR UserPtr
  246.  
  247.         This is a pointer provided for your own use.  This parameter is
  248.         ignored by SmartFields.
  249.  
  250.     LONG Reserved1, Reserved2
  251.  
  252.         These parameters were provided for future expansion.  Initialize
  253.         these parameters to zero and do not modify them.
  254.  
  255.  
  256. struct FieldHeader
  257. ------------------
  258.  
  259. This structure should be globally defined in your calling program, one
  260. structure for each set of fields in a window.  Note that you can have
  261. multiple sets (lists) of fields for each window (although only one is
  262. recommended), but you can have only one window per field list.  If you elect
  263. to open the devices required for console use yourself, be sure to place their
  264. pointers in this structure so that the SmartFields functions can use them.
  265. The FieldHeader structure has the following format:
  266.  
  267.     struct FieldHeader {
  268.         struct Window *Window;
  269.         struct MsgPort *WritePort;
  270.         struct IOStdReq *WriteReq;
  271.         struct MsgPort *ReadPort;
  272.         struct IOStdReq *ReadReq;
  273.         LONG   ConsoleError;
  274.         UBYTE  *Buffer;
  275.         struct FieldMask *Mask;
  276.         SHORT  TypeMode;
  277.         APTR   UserPtr;
  278.         LONG   Reserved1;
  279.         LONG   Reserved2;
  280.         struct Field *FirstField;
  281.         struct Field *FinalField;
  282.         struct Field *CurrentField;
  283.         SHORT  BufferPos;
  284.     };
  285.  
  286.     The individual elements are defined as follows:
  287.  
  288.     struct Window *Window
  289.  
  290.         This is a pointer to the window containing the fields.  Note that you
  291.         cannot link fields from different windows in the same list.  It is
  292.         the responsibility of your calling program to open and close the
  293.         window.
  294.  
  295.     struct MsgPort *WritePort
  296.     struct IOStdReq *WriteReq
  297.     struct MsgPort *ReadPort
  298.     struct IOStdReq *ReadReq
  299.  
  300.         These are the message ports and read/write requests that need to be
  301.         set up for the window's console device.  This is all handled by the
  302.         field_open() and field_close() functions if you wish to let
  303.         SmartFields do the dirty work for you.  The field_open() function
  304.         sets these values to NULL then attempts to open each one.  The
  305.         field_close() function then attempts to close each device with a non-
  306.         zero pointer.
  307.  
  308.     LONG ConsoleError
  309.  
  310.         This is a flag containing the success of opening the console device
  311.         for the window.  If the device could not be opened or has not been
  312.         opened, it will contain the value of CONSOLE_ERROR as defined in
  313.         console/console.h.  The field_open() and field_close() functions will
  314.         open and close the console device if you choose.
  315.  
  316.     UBYTE *Buffer
  317.  
  318.         This is a pointer to the buffer which is used for console input.  It
  319.         is the responsibility of the calling program to declare a buffer of
  320.         at least CONSOLE_BUFFER_SIZE as defined in console/console.h to be
  321.         used by the SmartFields program.  This buffer is handy because you
  322.         can also use it for any other function in your calling program that
  323.         needs a very temporary buffer.  By "very" we mean that any call to a
  324.         SmartFields function may trash its contents.
  325.  
  326.     struct FieldMask *Mask
  327.  
  328.         This is a pointer to the input mask used by the console_input()
  329.         function to filter input.  See the FieldMask structure definition for
  330.         more information.  If you specify NULL for this parameter, no input
  331.         checking will be done and all console input will be accepted.  If you
  332.         wish to mask out input for individual fields, use the Mask parameter
  333.         in the Field structure.
  334.  
  335.     SHORT TypeMode
  336.  
  337.         This is the current type mode, either INSERT_TYPE_MODE or
  338.         TYPEOVER_TYPE_MODE as defined in console/console.h.  In Insert type
  339.         mode, all characters you type are inserted in the field at the
  340.         current cursor position, and all characters at and to the right of
  341.         the cursor are moved one character position to the right to make room
  342.         for the character typed.  The cursor does not move.  If you attempt
  343.         to type in a field that is full, the screen will flash indicating
  344.         that there is no more room to insert characters.  This is the mode
  345.         that the Intuition string gadgets use.  In typeover mode, however,
  346.         all characters you type replace the character under the cursor, and
  347.         the cursor moves one character position to the right.  If the field
  348.         is full, the character you type just replaces the final character in
  349.         the field.  This is initialized for you by the field_open() function.
  350.  
  351.     APTR UserPtr
  352.  
  353.         This is a pointer provided for your own use and is ignored by
  354.         SmartFields.
  355.  
  356.     LONG Reserved1, Reserved2
  357.  
  358.         These variables are provided for future expansion.
  359.  
  360.     struct Field *FirstField
  361.  
  362.         This contains a pointer to the first field in the field list.  This
  363.         is automatically filled in by the field_open() function.
  364.  
  365.     struct Field *FinalField
  366.  
  367.         This contains a pointer to the final field in the field list.
  368.  
  369.     struct Field *CurrentField
  370.  
  371.         This contains a pointer to the current field in the field list.  If
  372.         there is no current field, then this pointer will be NULL.
  373.  
  374.     SHORT BufferPos
  375.  
  376.         This is a storage variable used to pass values between the
  377.         field_click() function and your calling program.  See the
  378.         field_click() function description for more information on its use.
  379.  
  380.  
  381. struct FieldMask
  382. ----------------
  383.  
  384. This structure is used by the field_input() function to determine if the
  385. character typed is accepted in the current field.  You define a FieldMask
  386. structure for each field in which you wish to restrict input.  Normally a
  387. field will accept any displayable character as input.  If you wish to
  388. restrict the field's input in any way, for example limiting it to only
  389. alphabetic or numeric characters, you would define a FieldMask structure for
  390. that field and set the Mask parameter of the field's Field structure equal to
  391. the address of the mask you create.  More than one field may share the same
  392. mask.  The FieldMask structure has the following format:
  393.  
  394.     struct FieldMask {
  395.         ULONG Element[MASK_ELEMENTS];
  396.     };
  397.  
  398. MASK_ELEMENTS is defined in console/field.h as 8.  Thus there are 8 long
  399. integers of 32-bits each or 256 total bits in the FieldMask structure, which
  400. just happens to correspond to the number of ASCII characters.  While it is
  401. true that not all 256 ASCII characters are displayable, having this format
  402. allows the mask creation and verification functions to use bit shifts instead
  403. of time-consuming multiplication and division.
  404.  
  405. Upon user input, the field_input() function checks to see if the current
  406. field has a mask.  If it does, it checks whether the bit in the mask
  407. corresponding to the character input has been set to 1.  If it has (and there
  408. is room for the character in the field), the character is placed in the
  409. field.  If the corresponding bit is set to zero, then the screen will flash.
  410. Note that this applies only to displayable characters and not to any control
  411. code or function key.
  412.  
  413. This structure can also be used by the console_input() function to restrict
  414. all console input.  You define a FieldMask structure and record its address
  415. in the Mask parameter of either the FieldHeader or ConsoleHeader structure
  416. (depending on which structure you are using).
  417.  
  418.  
  419. struct ConsoleHeader
  420. --------------------
  421.  
  422. The elements have the same meaning as in the FieldHeader structure.  They
  423. have the following format:
  424.  
  425.     struct ConsoleHeader {
  426.         struct Window *Window;
  427.         struct MsgPort *WritePort;
  428.         struct IOStdReq *WriteReq;
  429.         struct MsgPort *ReadPort;
  430.         struct IOStdReq *ReadReq;
  431.         LONG   ConsoleError;
  432.         UBYTE  *Buffer;
  433.         struct FieldMask *Mask;
  434.         SHORT  TypeMode;
  435.         APTR   UserPtr;
  436.         LONG   Reserved1;
  437.         LONG   Reserved2;
  438.     };
  439.  
  440. Notice that the ConsoleHeader structure is actually a subset of the
  441. FieldHeader structure.  This means that you can pass a pointer to a
  442. FieldHeader structure to any SmartFields function that is expecting a pointer
  443. to a ConsoleHeader structure (but NOT vice-versa).
  444.  
  445.  
  446. Structure Definitions  01/13/90
  447. © Copyright 1990 Timm Martin
  448. All Rights Reserved Worldwide
  449.  
  450. /*-- END --*/
  451.